package usbcali.edu.co.pqrs.dataaccess.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import usbcali.edu.co.pqrs.dataaccess.api.HibernateDaoImpl;
import usbcali.edu.co.pqrs.modelo.TipoSolicitudPqr;
import usbcali.edu.co.pqrs.modelo.dto.AnxsXTpSolDTO;
import usbcali.edu.co.pqrs.modelo.dto.MotReclXTpSolDTO;
import usbcali.edu.co.pqrs.modelo.dto.MotSolXTpSolDTO;

/**
 * A data access object (DAO) providing persistence and search support for
 * TipoSolicitudPqr entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see lidis.TipoSolicitudPqr
 */
@Scope("singleton")
@Repository("TipoSolicitudPqrDAO")
public class TipoSolicitudPqrDAO extends HibernateDaoImpl<TipoSolicitudPqr, Long>
    implements ITipoSolicitudPqrDAO {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(TipoSolicitudPqrDAO.class);
    @Resource
    private SessionFactory sessionFactory;

    public static ITipoSolicitudPqrDAO getFromApplicationContext(
        ApplicationContext ctx) {
        return (ITipoSolicitudPqrDAO) ctx.getBean("TipoSolicitudPqrDAO");
    }
    
    @SuppressWarnings("unchecked")
	@Override
	public List<AnxsXTpSolDTO> anexosXIdTipoSolicitud(Long idTipoSolicitud) throws Exception {
		
    	
		List<AnxsXTpSolDTO> list = null;
		
		try {
			
			Query query = getSession().getNamedQuery("anexos_id_tipo_solicitud");
			query.setParameter("pIdTipoSolicitud", idTipoSolicitud);
			query.setResultTransformer(Transformers.aliasToBean(AnxsXTpSolDTO.class));
			list = query.list();
			
		} catch (Exception e) {
			throw e;
		}
		
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MotSolXTpSolDTO> motSolXIdTipoSolicitud(Long idTipoSolicitud)
			throws Exception {

		List<MotSolXTpSolDTO> list = null;
		
		try {
			
			Query query = getSession().getNamedQuery("motivo_solicitud_id_tipo_solicitud");
			query.setParameter("pIdTipoSolicitud", idTipoSolicitud);
			query.setResultTransformer(Transformers.aliasToBean(MotSolXTpSolDTO.class));
			list = query.list();
			
		} catch (Exception e) {
			throw e;
		}
		
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MotReclXTpSolDTO> motReclXIdTipoSolicitud(Long idTipoSolicitud)
			throws Exception {

		List<MotReclXTpSolDTO> list = null;
		
		try {
			
			Query query = getSession().getNamedQuery("motivo_reclamacion_id_tipo_solicitud");
			query.setParameter("pIdTipoSolicitud", idTipoSolicitud);
			query.setResultTransformer(Transformers.aliasToBean(MotReclXTpSolDTO.class));
			list = query.list();
			
		} catch (Exception e) {
			throw e;
		}
		
		return list;
	}
}
